<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>Tp5框架整合七牛云上传视频 | Ahuang'Blog</title><meta name="author" content="Ahuang"><meta name="copyright" content="Ahuang"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="配置参数 123456789return [   &amp;#x27;ACCESSKEY&amp;#x27;  &#x3D;&gt;  &amp;#x27;&amp;#x27;,       &amp;#x27;SECRETKEY&amp;#x27;  &#x3D;&gt;  &amp;#x27;&amp;#x27;,       &amp;#x27;BUCKET&amp;#x27;     &#x3D;&gt;   &amp;#x27;&amp;#x27;,			&#x2F;&#x2F;空间名       &amp;#x27;DOMAIN&amp;#x2">
<meta property="og:type" content="article">
<meta property="og:title" content="Tp5框架整合七牛云上传视频">
<meta property="og:url" content="http://huangxiaochang.gitee.io/ahuang_blog/2019/09/28/018/index.html">
<meta property="og:site_name" content="Ahuang&#39;Blog">
<meta property="og:description" content="配置参数 123456789return [   &amp;#x27;ACCESSKEY&amp;#x27;  &#x3D;&gt;  &amp;#x27;&amp;#x27;,       &amp;#x27;SECRETKEY&amp;#x27;  &#x3D;&gt;  &amp;#x27;&amp;#x27;,       &amp;#x27;BUCKET&amp;#x27;     &#x3D;&gt;   &amp;#x27;&amp;#x27;,			&#x2F;&#x2F;空间名       &amp;#x27;DOMAIN&amp;#x2">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fastly.jsdelivr.net/gh/jerryc127/CDN@latest/cover/default_bg.png">
<meta property="article:published_time" content="2019-09-28T10:55:49.000Z">
<meta property="article:modified_time" content="2023-01-31T12:21:57.114Z">
<meta property="article:author" content="Ahuang">
<meta property="article:tag" content="七牛云上传">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fastly.jsdelivr.net/gh/jerryc127/CDN@latest/cover/default_bg.png"><link rel="shortcut icon" href="/ahuang_blog/img/favicon.ico"><link rel="canonical" href="http://huangxiaochang.gitee.io/ahuang_blog/2019/09/28/018/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta/><link rel="stylesheet" href="/ahuang_blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/ahuang_blog/',
  algolia: undefined,
  localSearch: {"path":"/ahuang_blog/search.xml","preload":true,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: {"limitDay":500,"position":"top","messagePrev":"It has been","messageNext":"days since the last update, the content of the article may be outdated."},
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":400},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Tp5框架整合七牛云上传视频',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2023-01-31 20:21:57'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = url => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      link.onload = () => resolve()
      link.onerror = () => reject()
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/blog/css/transpancy.css"><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/js-heo@1.0.11/mainColor/heoMainColor.css"><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/js-heo@1.0.11/categoryBar/categoryBar.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-clock/lib/clock.min.css" /><!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (false) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/ahuang_blog/img/Misaka.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/ahuang_blog/archives/"><div class="headline">文章</div><div class="length-num">51</div></a><a href="/ahuang_blog/tags/"><div class="headline">标签</div><div class="length-num">35</div></a><a href="/ahuang_blog/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/ahuang_blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/ahuang_blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/ahuang_blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/ahuang_blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/ahuang_blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg fixed" id="page-header" style="background-image: url('https://fastly.jsdelivr.net/gh/jerryc127/CDN@latest/cover/default_bg.png')"><nav id="nav"><span id="blog-info"><a href="/ahuang_blog/" title="Ahuang'Blog"><span class="site-name">Ahuang'Blog</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/ahuang_blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/ahuang_blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/ahuang_blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/ahuang_blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/ahuang_blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Tp5框架整合七牛云上传视频</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-09-28T10:55:49.000Z" title="发表于 2019-09-28 18:55:49">2019-09-28</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-01-31T12:21:57.114Z" title="更新于 2023-01-31 20:21:57">2023-01-31</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/ahuang_blog/categories/PHP/">PHP</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.8k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>10分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Tp5框架整合七牛云上传视频"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p>配置参数</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">return</span> [</span><br><span class="line">   <span class="string">&#x27;ACCESSKEY&#x27;</span>  =&gt;  <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">       <span class="string">&#x27;SECRETKEY&#x27;</span>  =&gt;  <span class="string">&#x27;&#x27;</span>,</span><br><span class="line">       <span class="string">&#x27;BUCKET&#x27;</span>     =&gt;   <span class="string">&#x27;&#x27;</span>,			//空间名</span><br><span class="line">       <span class="string">&#x27;DOMAIN&#x27;</span>     =&gt;   <span class="string">&#x27;&#x27;</span>, //空间对外域名</span><br><span class="line">       <span class="string">&#x27;HUBNAME&#x27;</span>    =&gt;    <span class="string">&#x27;&#x27;</span>,  </span><br><span class="line">       <span class="string">&#x27;qiniu_notify&#x27;</span>=&gt;	, //转码成功后的验证的回调地址</span><br><span class="line">       <span class="string">&#x27;pipeline&#x27;</span>  =&gt;  	<span class="string">&#x27;&#x27;</span> //转码是使用的队列名称</span><br><span class="line">];</span><br></pre></td></tr></table></figure>
<p>控制器操作</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 获取七牛云的token</span><br><span class="line"> */</span><br><span class="line">public <span class="keyword">function</span> <span class="function"><span class="title">qiniu_token</span></span>()</span><br><span class="line">&#123;</span><br><span class="line">  	//配置信息</span><br><span class="line">  	<span class="variable">$config</span> = Config(<span class="string">&#x27;Qiniu&#x27;</span>);</span><br><span class="line">  	//实例化类</span><br><span class="line">  	<span class="variable">$Qiniu</span> = new \Qu\Qiniu();</span><br><span class="line">    <span class="variable">$token</span> = <span class="variable">$Qiniu</span>::getToken(<span class="variable">$config</span>);</span><br><span class="line">    //ajax返回数据token</span><br><span class="line">    <span class="built_in">return</span> [<span class="string">&#x27;token&#x27;</span> =&gt; <span class="variable">$token</span>];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">/**</span><br><span class="line"> * 转吗</span><br><span class="line"> */</span><br><span class="line">public <span class="keyword">function</span> <span class="function"><span class="title">zm</span></span>()</span><br><span class="line">&#123;</span><br><span class="line">  	<span class="variable">$videoName</span> = input(<span class="string">&#x27;get.video_name&#x27;</span>);</span><br><span class="line">	<span class="variable">$duration</span> = input(<span class="string">&#x27;get.duration&#x27;</span>);</span><br><span class="line">    //配置信息</span><br><span class="line">    <span class="variable">$config</span> = Config(<span class="string">&#x27;Qiniu&#x27;</span>);</span><br><span class="line">	//实例化类</span><br><span class="line">	<span class="variable">$Qiniu</span> = new \Qu\Qiniu();</span><br><span class="line">	<span class="variable">$video_url</span> = <span class="variable">$Qiniu</span>::qiniuzm(<span class="variable">$config</span>,<span class="variable">$videoName</span>,<span class="variable">$duration</span>);</span><br><span class="line">	//ajax返回数据video_url</span><br><span class="line">	<span class="built_in">return</span> array(<span class="string">&#x27;video_url&#x27;</span>=&gt;<span class="variable">$video_url</span>);</span><br><span class="line">&#125;</span><br><span class="line">/**</span><br><span class="line"> * 转码成功后回调地址</span><br><span class="line"> */</span><br><span class="line">public <span class="keyword">function</span> <span class="function"><span class="title">del</span></span>()</span><br><span class="line">&#123;</span><br><span class="line">    <span class="variable">$videoName</span> = input(<span class="string">&#x27;get.video_name&#x27;</span>);</span><br><span class="line">    //配置信息</span><br><span class="line">    <span class="variable">$config</span> = Config(<span class="string">&#x27;Qiniu&#x27;</span>);</span><br><span class="line">    <span class="variable">$Qiniu</span> = new \Qu\Qiniu();</span><br><span class="line">    <span class="variable">$Qiniu</span>::del(<span class="variable">$config</span>,<span class="variable">$videoName</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<p>H5端代码</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br></pre></td><td class="code"><pre><span class="line">$(<span class="function"><span class="title">function</span></span>() &#123;</span><br><span class="line">  	<span class="keyword">function</span> <span class="function"><span class="title">getTokenMessage</span></span>() &#123;</span><br><span class="line">      	var token = &#123;&#125;;</span><br><span class="line">      	//获取七牛云token</span><br><span class="line">      	$.ajax(&#123;</span><br><span class="line">      		url:<span class="string">&#x27;/qiniu_token&#x27;</span>,</span><br><span class="line">      		async:<span class="literal">false</span>,</span><br><span class="line">      		success:<span class="keyword">function</span> (data) &#123;</span><br><span class="line">      		token.token = data.token;</span><br><span class="line">      &#125;</span><br><span class="line">	&#125;)</span><br><span class="line">	<span class="built_in">return</span> token;</span><br><span class="line">&#125;</span><br><span class="line">var uploader = Qiniu.uploader(&#123;</span><br><span class="line">	runtimes: <span class="string">&#x27;html5,flash,html4&#x27;</span>,</span><br><span class="line">	browse_button: <span class="string">&#x27;pickfiles&#x27;</span>,</span><br><span class="line">	container: <span class="string">&#x27;container&#x27;</span>,</span><br><span class="line">	drop_element: <span class="string">&#x27;container&#x27;</span>,</span><br><span class="line">	max_file_size: <span class="string">&#x27;1000mb&#x27;</span>,</span><br><span class="line">	flash_swf_url: <span class="string">&#x27;bower_components/plupload/js/Moxie.swf&#x27;</span>,</span><br><span class="line">	dragdrop: <span class="literal">true</span>,</span><br><span class="line">	chunk_size: <span class="string">&#x27;4mb&#x27;</span>,</span><br><span class="line">	multi_selection: !(mOxie.Env.OS.toLowerCase()===<span class="string">&quot;ios&quot;</span>),</span><br><span class="line">	//uptoken_url: <span class="string">&#x27;/index.php/Home/Source/qiniu_token&#x27;</span>,</span><br><span class="line">	uptoken:getTokenMessage().token,</span><br><span class="line">	//persistentOps:<span class="string">&quot;avthumb/mp4;avthumb/m3u8/noDomain/1/segtime/15/vb/440k&quot;</span>,</span><br><span class="line">	domain: $(<span class="string">&#x27;#domain&#x27;</span>).val(),</span><br><span class="line">	get_new_uptoken: <span class="literal">false</span>,</span><br><span class="line">	auto_start: <span class="literal">true</span>,</span><br><span class="line">	log_level: 5,</span><br><span class="line">	init: &#123;</span><br><span class="line">	<span class="string">&#x27;FilesAdded&#x27;</span>: <span class="keyword">function</span>(up, files) &#123;</span><br><span class="line">	$(<span class="string">&#x27;table&#x27;</span>).show();</span><br><span class="line">	$(<span class="string">&#x27;#success&#x27;</span>).hide();</span><br><span class="line">	plupload.each(files, <span class="keyword">function</span>(file) &#123;</span><br><span class="line">	//var objfile=$.parseJSON(file);</span><br><span class="line">	// alert(file.id);</span><br><span class="line">	// alert(file.getSource);</span><br><span class="line">	// console.log(<span class="string">&quot;file&quot;</span>,file);</span><br><span class="line">	var progress = new FileProgress(file, <span class="string">&#x27;fsUploadProgress&#x27;</span>);</span><br><span class="line">	progress.setStatus(<span class="string">&quot;等待...&quot;</span>);</span><br><span class="line">	progress.bindUploadCancel(up);</span><br><span class="line">	&#125;);</span><br><span class="line">&#125;,</span><br><span class="line"><span class="string">&#x27;BeforeUpload&#x27;</span>: <span class="keyword">function</span>(up, file) &#123;</span><br><span class="line">var progress = new FileProgress(file, <span class="string">&#x27;fsUploadProgress&#x27;</span>);</span><br><span class="line">var chunk_size = plupload.parseSize(this.getOption(<span class="string">&#x27;chunk_size&#x27;</span>));</span><br><span class="line"><span class="keyword">if</span> (up.runtime === <span class="string">&#x27;html5&#x27;</span> &amp;&amp; chunk_size) &#123;</span><br><span class="line">progress.setChunkProgess(chunk_size);</span><br><span class="line">&#125;</span><br><span class="line">&#125;,</span><br><span class="line"><span class="string">&#x27;UploadProgress&#x27;</span>: <span class="keyword">function</span>(up, file) &#123;</span><br><span class="line">var progress = new FileProgress(file, <span class="string">&#x27;fsUploadProgress&#x27;</span>);</span><br><span class="line">var chunk_size = plupload.parseSize(this.getOption(<span class="string">&#x27;chunk_size&#x27;</span>));</span><br><span class="line">progress.setProgress(file.percent + <span class="string">&quot;%&quot;</span>, file.speed, chunk_size);</span><br><span class="line">&#125;,</span><br><span class="line"><span class="string">&#x27;UploadComplete&#x27;</span>: <span class="function"><span class="title">function</span></span>() &#123;</span><br><span class="line">$(<span class="string">&#x27;#success&#x27;</span>).show();</span><br><span class="line">&#125;,</span><br><span class="line"><span class="string">&#x27;FileUploaded&#x27;</span>: <span class="keyword">function</span>(up, file, info) &#123;</span><br><span class="line">var progress = new FileProgress(file, <span class="string">&#x27;fsUploadProgress&#x27;</span>);</span><br><span class="line">progress.setComplete(up, info);</span><br><span class="line">//</span><br><span class="line">//var domain = up.getOption(<span class="string">&#x27;domain&#x27;</span>);</span><br><span class="line">//var res = <span class="built_in">eval</span>(<span class="string">&#x27;(&#x27;</span> + info + <span class="string">&#x27;)&#x27;</span>);</span><br><span class="line">// var sourceLink = domain + res.key;//获取上传文件的链接地址</span><br><span class="line">//console.log(info);</span><br><span class="line">var video_info = JSON.parse(info);</span><br><span class="line"></span><br><span class="line">//获取视频信息</span><br><span class="line">//http://oslyovppn.bkt.clouddn.com/hengzhang-2017-05-17-591beeebeef79.mp4?avinfo</span><br><span class="line">//视频路径</span><br><span class="line">var domain = $(<span class="string">&#x27;#domain&#x27;</span>).val();</span><br><span class="line">var url = domain+<span class="string">&#x27;/&#x27;</span>+video_info.key+<span class="string">&#x27;?avinfo&#x27;</span>;</span><br><span class="line">//</span><br><span class="line">$.get(url,&#123;&#125;,<span class="keyword">function</span>(res)&#123;</span><br><span class="line">var duration = res.format.duration;</span><br><span class="line">//发送ajax转码</span><br><span class="line">$.get(<span class="string">&#x27;&#123;:Url(&quot;zm&quot;)&#125;&#x27;</span>,&#123;<span class="string">&#x27;video_name&#x27;</span>:video_info.key,<span class="string">&#x27;duration&#x27;</span>:duration&#125;,<span class="keyword">function</span>(res)&#123;</span><br><span class="line">//判断是否已上传视频</span><br><span class="line">var old_video = $(<span class="string">&#x27;#video&#x27;</span>).val();</span><br><span class="line"><span class="keyword">if</span>(old_video == <span class="string">&quot;&quot;</span>)&#123;</span><br><span class="line">$(<span class="string">&#x27;#video&#x27;</span>).val(domain+res.video_url);</span><br><span class="line">&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">$(<span class="string">&#x27;#video&#x27;</span>).val(old_video+<span class="string">&#x27;&amp;&#x27;</span>+domain+res.video_url);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">//删除转码前的视频</span><br><span class="line">$.get(<span class="string">&#x27;&#123;:Url(&quot;del&quot;)&#125;&#x27;</span>,&#123;<span class="string">&#x27;video_name&#x27;</span>:video_info.key&#125;,<span class="keyword">function</span>(res)&#123;</span><br><span class="line"></span><br><span class="line">&#125;);</span><br><span class="line">&#125;);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">&#125;,</span><br><span class="line"><span class="string">&#x27;Error&#x27;</span>: <span class="keyword">function</span>(up, err, errTip) &#123;</span><br><span class="line">$(<span class="string">&#x27;table&#x27;</span>).show();</span><br><span class="line">var progress = new FileProgress(err.file, <span class="string">&#x27;fsUploadProgress&#x27;</span>);</span><br><span class="line">progress.setError();</span><br><span class="line">progress.setStatus(errTip);</span><br><span class="line">&#125;</span><br><span class="line">&#125;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">uploader.bind(<span class="string">&#x27;FileUploaded&#x27;</span>, <span class="function"><span class="title">function</span></span>() &#123;</span><br><span class="line">//console.log(<span class="string">&#x27;hello man,a file is uploaded&#x27;</span>);</span><br><span class="line">&#125;);</span><br><span class="line">$(<span class="string">&#x27;#container&#x27;</span>).on(</span><br><span class="line"><span class="string">&#x27;dragenter&#x27;</span>,</span><br><span class="line"><span class="keyword">function</span>(e) &#123;</span><br><span class="line">e.preventDefault();</span><br><span class="line">$(<span class="string">&#x27;#container&#x27;</span>).addClass(<span class="string">&#x27;draging&#x27;</span>);</span><br><span class="line">e.stopPropagation();</span><br><span class="line">&#125;</span><br><span class="line">).on(<span class="string">&#x27;drop&#x27;</span>, <span class="keyword">function</span>(e) &#123;</span><br><span class="line">e.preventDefault();</span><br><span class="line">$(<span class="string">&#x27;#container&#x27;</span>).removeClass(<span class="string">&#x27;draging&#x27;</span>);</span><br><span class="line">e.stopPropagation();</span><br><span class="line">&#125;).on(<span class="string">&#x27;dragleave&#x27;</span>, <span class="keyword">function</span>(e) &#123;</span><br><span class="line">e.preventDefault();</span><br><span class="line">$(<span class="string">&#x27;#container&#x27;</span>).removeClass(<span class="string">&#x27;draging&#x27;</span>);</span><br><span class="line">e.stopPropagation();</span><br><span class="line">&#125;).on(<span class="string">&#x27;dragover&#x27;</span>, <span class="keyword">function</span>(e) &#123;</span><br><span class="line">e.preventDefault();</span><br><span class="line">$(<span class="string">&#x27;#container&#x27;</span>).addClass(<span class="string">&#x27;draging&#x27;</span>);</span><br><span class="line">e.stopPropagation();</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">$(<span class="string">&#x27;#show_code&#x27;</span>).on(<span class="string">&#x27;click&#x27;</span>, <span class="function"><span class="title">function</span></span>() &#123;</span><br><span class="line">$(<span class="string">&#x27;#myModal-code&#x27;</span>).modal();</span><br><span class="line">$(<span class="string">&#x27;pre code&#x27;</span>).each(<span class="keyword">function</span>(i, e) &#123;</span><br><span class="line">hljs.highlightBlock(e);</span><br><span class="line">&#125;);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">$(<span class="string">&#x27;body&#x27;</span>).on(<span class="string">&#x27;click&#x27;</span>, <span class="string">&#x27;table button.btn&#x27;</span>, <span class="function"><span class="title">function</span></span>() &#123;</span><br><span class="line">$(this).parents(<span class="string">&#x27;tr&#x27;</span>).next().toggle();</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">var getRotate = <span class="keyword">function</span>(url) &#123;</span><br><span class="line"><span class="keyword">if</span> (!url) &#123;</span><br><span class="line"><span class="built_in">return</span> 0;</span><br><span class="line">&#125;</span><br><span class="line">var arr = url.split(<span class="string">&#x27;/&#x27;</span>);</span><br><span class="line"><span class="keyword">for</span> (var i = 0, len = arr.length; i &lt; len; i++) &#123; <span class="keyword">if</span> (arr[i] === <span class="string">&#x27;rotate&#x27;</span>) &#123; <span class="built_in">return</span> parseInt(arr[i + 1], 10); &#125; &#125; <span class="built_in">return</span> 0; &#125;; $(<span class="string">&#x27;#myModal-img .modal-body-footer&#x27;</span>).find(<span class="string">&#x27;a&#x27;</span>).on(<span class="string">&#x27;click&#x27;</span>, <span class="function"><span class="title">function</span></span>() &#123; var img = $(<span class="string">&#x27;#myModal-img&#x27;</span>).find(<span class="string">&#x27;.modal-body img&#x27;</span>); var key = img.data(<span class="string">&#x27;key&#x27;</span>); var oldUrl = img.attr(<span class="string">&#x27;src&#x27;</span>); var originHeight = parseInt(img.data(<span class="string">&#x27;h&#x27;</span>), 10);           var fopArr = []; var rotate = getRotate(oldUrl); <span class="keyword">if</span> (!$(this).hasClass(<span class="string">&#x27;no-disable-click&#x27;</span>)) &#123; $(this).addClass(<span class="string">&#x27;disabled&#x27;</span>).siblings().removeClass(<span class="string">&#x27;disabled&#x27;</span>); <span class="keyword">if</span> ($(this).data(<span class="string">&#x27;imagemogr&#x27;</span>) !== <span class="string">&#x27;no-rotate&#x27;</span>) &#123; fopArr.push(&#123; <span class="string">&#x27;fop&#x27;</span>: <span class="string">&#x27;imageMogr2&#x27;</span>, <span class="string">&#x27;auto-orient&#x27;</span>: <span class="literal">true</span>, <span class="string">&#x27;strip&#x27;</span>: <span class="literal">true</span>, <span class="string">&#x27;rotate&#x27;</span>: rotate, <span class="string">&#x27;format&#x27;</span>: <span class="string">&#x27;png&#x27;</span> &#125;); &#125; &#125; <span class="keyword">else</span> &#123; $(this).siblings().removeClass(<span class="string">&#x27;disabled&#x27;</span>); var imageMogr = $(this).data(<span class="string">&#x27;imagemogr&#x27;</span>); <span class="keyword">if</span> (imageMogr === <span class="string">&#x27;left&#x27;</span>) &#123; rotate = rotate - 90 &lt; 0 ? rotate + 270 : rotate - 90; &#125; <span class="keyword">else</span> <span class="keyword">if</span> (imageMogr === <span class="string">&#x27;right&#x27;</span>) &#123; rotate = rotate + 90 &gt; 360 ? rotate - 270 : rotate + 90;</span><br><span class="line">&#125;</span><br><span class="line">fopArr.push(&#123;</span><br><span class="line"><span class="string">&#x27;fop&#x27;</span>: <span class="string">&#x27;imageMogr2&#x27;</span>,</span><br><span class="line"><span class="string">&#x27;auto-orient&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line"><span class="string">&#x27;strip&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line"><span class="string">&#x27;rotate&#x27;</span>: rotate,</span><br><span class="line"><span class="string">&#x27;format&#x27;</span>: <span class="string">&#x27;png&#x27;</span></span><br><span class="line">&#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$(<span class="string">&#x27;#myModal-img .modal-body-footer&#x27;</span>).find(<span class="string">&#x27;a.disabled&#x27;</span>).each(<span class="function"><span class="title">function</span></span>() &#123;</span><br><span class="line"></span><br><span class="line">var watermark = $(this).data(<span class="string">&#x27;watermark&#x27;</span>);</span><br><span class="line">var imageView = $(this).data(<span class="string">&#x27;imageview&#x27;</span>);</span><br><span class="line">var imageMogr = $(this).data(<span class="string">&#x27;imagemogr&#x27;</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> (watermark) &#123;</span><br><span class="line">fopArr.push(&#123;</span><br><span class="line">fop: <span class="string">&#x27;watermark&#x27;</span>,</span><br><span class="line">mode: 1,</span><br><span class="line">image: <span class="string">&#x27;http://www.b1.qiniudn.com/images/logo-2.png&#x27;</span>,</span><br><span class="line">dissolve: 100,</span><br><span class="line">gravity: watermark,</span><br><span class="line">dx: 100,</span><br><span class="line">dy: 100</span><br><span class="line">&#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> (imageView) &#123;</span><br><span class="line">var height;</span><br><span class="line">switch (imageView) &#123;</span><br><span class="line"><span class="keyword">case</span> <span class="string">&#x27;large&#x27;</span>:</span><br><span class="line">height = originHeight;</span><br><span class="line"><span class="built_in">break</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="string">&#x27;middle&#x27;</span>:</span><br><span class="line">height = originHeight * 0.5;</span><br><span class="line"><span class="built_in">break</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="string">&#x27;small&#x27;</span>:</span><br><span class="line">height = originHeight * 0.1;</span><br><span class="line"><span class="built_in">break</span>;</span><br><span class="line">default:</span><br><span class="line">height = originHeight;</span><br><span class="line"><span class="built_in">break</span>;</span><br><span class="line">&#125;</span><br><span class="line">fopArr.push(&#123;</span><br><span class="line">fop: <span class="string">&#x27;imageView2&#x27;</span>,</span><br><span class="line">mode: 3,</span><br><span class="line">h: parseInt(height, 10),</span><br><span class="line">q: 100,</span><br><span class="line">format: <span class="string">&#x27;png&#x27;</span></span><br><span class="line">&#125;);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> (imageMogr === <span class="string">&#x27;no-rotate&#x27;</span>) &#123;</span><br><span class="line">fopArr.push(&#123;</span><br><span class="line"><span class="string">&#x27;fop&#x27;</span>: <span class="string">&#x27;imageMogr2&#x27;</span>,</span><br><span class="line"><span class="string">&#x27;auto-orient&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line"><span class="string">&#x27;strip&#x27;</span>: <span class="literal">true</span>,</span><br><span class="line"><span class="string">&#x27;rotate&#x27;</span>: 0,</span><br><span class="line"><span class="string">&#x27;format&#x27;</span>: <span class="string">&#x27;png&#x27;</span></span><br><span class="line">&#125;);</span><br><span class="line">&#125;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">var newUrl = Qiniu.pipeline(fopArr, key);</span><br><span class="line"></span><br><span class="line">var newImg = new Image();</span><br><span class="line">img.attr(<span class="string">&#x27;src&#x27;</span>, <span class="string">&#x27;images/loading.gif&#x27;</span>);</span><br><span class="line">newImg.onload = <span class="function"><span class="title">function</span></span>() &#123;</span><br><span class="line">img.attr(<span class="string">&#x27;src&#x27;</span>, newUrl);</span><br><span class="line">img.parent(<span class="string">&#x27;a&#x27;</span>).attr(<span class="string">&#x27;href&#x27;</span>, newUrl);</span><br><span class="line">&#125;;</span><br><span class="line">newImg.src = newUrl;</span><br><span class="line"><span class="built_in">return</span> <span class="literal">false</span>;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>



<p>封装的七牛云转码工具类</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br></pre></td><td class="code"><pre><span class="line">namespace  Qu;</span><br><span class="line"></span><br><span class="line">class Qiniu</span><br><span class="line">&#123;</span><br><span class="line">	//配置参数</span><br><span class="line">	protected <span class="variable">$Qiniu_config</span> = [];</span><br><span class="line">	protected <span class="variable">$videoName</span>; //视频名称</span><br><span class="line">	protected <span class="variable">$duration</span>; //</span><br><span class="line"></span><br><span class="line">	//单例模式</span><br><span class="line">	private static <span class="variable">$Auth</span>; </span><br><span class="line">	public static <span class="keyword">function</span> Auth(<span class="variable">$accessKey</span>, <span class="variable">$secretKey</span>)</span><br><span class="line">	&#123;</span><br><span class="line">	  <span class="keyword">if</span>(self::<span class="variable">$Auth</span> === null)&#123;</span><br><span class="line">	    self::<span class="variable">$Auth</span> = new \Qiniu\Auth(<span class="variable">$accessKey</span>, <span class="variable">$secretKey</span>);</span><br><span class="line">	  &#125;</span><br><span class="line">	  <span class="built_in">return</span> self::<span class="variable">$Auth</span>;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	/**</span><br><span class="line">	 * 获取七牛云上传视频的token</span><br><span class="line">	 */</span><br><span class="line">	public static <span class="keyword">function</span> getToken(<span class="variable">$Qiniu_config</span>)</span><br><span class="line">	&#123;</span><br><span class="line">	    import(<span class="string">&#x27;Qiniu.functions&#x27;</span>);</span><br><span class="line">	    // 用于签名的公钥和私钥</span><br><span class="line">	    <span class="variable">$accessKey</span> = <span class="variable">$Qiniu_config</span>[<span class="string">&#x27;ACCESSKEY&#x27;</span>];</span><br><span class="line">	    <span class="variable">$secretKey</span> = <span class="variable">$Qiniu_config</span>[<span class="string">&#x27;SECRETKEY&#x27;</span>];</span><br><span class="line">	    // 构建鉴权对象</span><br><span class="line">	    <span class="variable">$auth</span> = self::Auth(<span class="variable">$accessKey</span>, <span class="variable">$secretKey</span>);</span><br><span class="line">	    // 要上传的空间</span><br><span class="line">	    <span class="variable">$bucket</span> = <span class="variable">$Qiniu_config</span>[<span class="string">&#x27;BUCKET&#x27;</span>];</span><br><span class="line">	    // 生成上传 Token</span><br><span class="line">	    <span class="built_in">return</span> <span class="variable">$auth</span>-&gt;uploadToken(<span class="variable">$bucket</span>);</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">	  /**</span><br><span class="line">	   * 七牛转码</span><br><span class="line">	   */</span><br><span class="line">	public static <span class="keyword">function</span> qiniuzm(<span class="variable">$Qiniu_config</span>,<span class="variable">$videoName</span>=<span class="string">&quot;&quot;</span>,<span class="variable">$duration</span>=0)</span><br><span class="line">	&#123;</span><br><span class="line">	    //对已经上传到七牛的视频发起异步转码操作</span><br><span class="line">	  	import(<span class="string">&#x27;Qiniu.functions&#x27;</span>);</span><br><span class="line">	    // 用于签名的公钥和私钥</span><br><span class="line">	    <span class="variable">$accessKey</span> = <span class="variable">$Qiniu_config</span>[<span class="string">&#x27;ACCESSKEY&#x27;</span>];</span><br><span class="line">	    <span class="variable">$secretKey</span> = <span class="variable">$Qiniu_config</span>[<span class="string">&#x27;SECRETKEY&#x27;</span>];</span><br><span class="line">	  	<span class="variable">$auth</span> = self::Auth(<span class="variable">$accessKey</span>, <span class="variable">$secretKey</span>);</span><br><span class="line">	  	//要转码的文件所在的空间和文件名</span><br><span class="line">	  	<span class="variable">$bucket</span> = <span class="variable">$Qiniu_config</span>[<span class="string">&#x27;BUCKET&#x27;</span>];</span><br><span class="line">	  	//回调地址</span><br><span class="line">	    //<span class="variable">$notify_url</span> = <span class="variable">$Qiniu_config</span>[<span class="string">&#x27;qiniu_notify&#x27;</span>];</span><br><span class="line">	  	//转码是使用的队列名称</span><br><span class="line">	  	<span class="variable">$pipeline</span> = <span class="variable">$Qiniu_config</span>[<span class="string">&#x27;pipeline&#x27;</span>];</span><br><span class="line">	  	<span class="variable">$pfop</span> = new \Qiniu\Processing\PersistentFop(<span class="variable">$auth</span>, <span class="variable">$bucket</span>, <span class="variable">$pipeline</span>);</span><br><span class="line"></span><br><span class="line">	  	<span class="variable">$fops</span> = <span class="string">&quot;avthumb/mp4/ab/160k/ar/44100/acodec/libfaac/r/30/vb/2400k/vcodec/libx264/s/1280x720/autoscale/1/stripmeta/0&quot;</span>;</span><br><span class="line">	  	//转换后的文件名</span><br><span class="line">	  	//名称前缀</span><br><span class="line">	  	<span class="variable">$name_qz</span> = <span class="variable">$pipeline</span>;</span><br><span class="line">	  	<span class="variable">$savekey</span> = \Qiniu\base64_urlSafeEncode(<span class="variable">$bucket</span>.<span class="string">&#x27;:&#x27;</span>.<span class="variable">$name_qz</span>.<span class="string">&#x27;_&#x27;</span>.<span class="variable">$videoName</span>);</span><br><span class="line">	  	<span class="variable">$fops</span> = <span class="variable">$fops</span>.<span class="string">&#x27;|saveas/&#x27;</span>.<span class="variable">$savekey</span>;</span><br><span class="line">	  	<span class="variable">$pfop</span>-&gt;execute(<span class="variable">$videoName</span>, <span class="variable">$fops</span>);</span><br><span class="line">	  	list(<span class="variable">$id</span>, <span class="variable">$err</span>) =<span class="variable">$pfop</span>-&gt;execute(<span class="variable">$videoName</span>, <span class="variable">$fops</span>);</span><br><span class="line">	  	// <span class="keyword">if</span> (<span class="variable">$err</span> == null) &#123;</span><br><span class="line">	 	//      	<span class="variable">$PersistentFop</span> = new \Qiniu\Processing\PersistentFop(<span class="variable">$auth</span>, <span class="variable">$bucket</span>);</span><br><span class="line">		//   		// 触发持久化处理后返回的 Id</span><br><span class="line">		//   		// 通过persistentId查询该 触发持久化处理的状态</span><br><span class="line">		//   		<span class="variable">$status</span> = <span class="variable">$PersistentFop</span>::status(<span class="variable">$id</span>);</span><br><span class="line">		//   		dump(<span class="variable">$status</span>);</span><br><span class="line">	 	//  	&#125;</span><br><span class="line">	  	//视频的url</span><br><span class="line">	  	<span class="built_in">return</span> <span class="variable">$name_qz</span>.<span class="string">&#x27;_&#x27;</span>.<span class="variable">$videoName</span>;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">  	/**</span><br><span class="line">   	* 删除转码前的视频</span><br><span class="line">   	*/</span><br><span class="line">  	public static <span class="keyword">function</span> del(<span class="variable">$Qiniu_config</span>,<span class="variable">$videoName</span>=<span class="string">&quot;&quot;</span>)</span><br><span class="line">  	&#123;</span><br><span class="line">    	//对已经上传到七牛的视频发起异步转码操作</span><br><span class="line">  		import(<span class="string">&#x27;Qiniu.functions&#x27;</span>);</span><br><span class="line">    	// 用于签名的公钥和私钥</span><br><span class="line">    	<span class="variable">$accessKey</span> = <span class="variable">$Qiniu_config</span>[<span class="string">&#x27;ACCESSKEY&#x27;</span>];</span><br><span class="line">    	<span class="variable">$secretKey</span> = <span class="variable">$Qiniu_config</span>[<span class="string">&#x27;SECRETKEY&#x27;</span>];</span><br><span class="line">  		<span class="variable">$auth</span> = self::Auth(<span class="variable">$accessKey</span>, <span class="variable">$secretKey</span>);</span><br><span class="line">    	//删除转码前的文件</span><br><span class="line">  		//初始化BucketManager</span><br><span class="line">  		<span class="variable">$bucketMgr</span> = new \Qiniu\Storage\BucketManager(<span class="variable">$auth</span>);</span><br><span class="line">  		<span class="variable">$bucket</span> = <span class="variable">$Qiniu_config</span>[<span class="string">&#x27;BUCKET&#x27;</span>];</span><br><span class="line">  		//删除<span class="variable">$bucket</span> 中的文件 <span class="variable">$key</span></span><br><span class="line">  		<span class="variable">$bucketMgr</span>-&gt;delete(<span class="variable">$bucket</span>, <span class="variable">$videoName</span>);</span><br><span class="line">  	&#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://huangxiaochang.gitee.io/ahuang_blog">Ahuang</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://huangxiaochang.gitee.io/ahuang_blog/2019/09/28/018/">http://huangxiaochang.gitee.io/ahuang_blog/2019/09/28/018/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://huangxiaochang.gitee.io/ahuang_blog" target="_blank">Ahuang'Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/ahuang_blog/tags/%E4%B8%83%E7%89%9B%E4%BA%91%E4%B8%8A%E4%BC%A0/">七牛云上传</a></div><div class="post_share"></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/ahuang_blog/2019/11/25/011/" title="第三方登录之QQ登录"><img class="cover" src="https://fastly.jsdelivr.net/gh/jerryc127/CDN@latest/cover/default_bg.png" onerror="onerror=null;src='/ahuang_blog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">第三方登录之QQ登录</div></div></a></div><div class="next-post pull-right"><a href="/ahuang_blog/2019/07/03/010/" title="Tp5整合生成条形码"><img class="cover" src="https://fastly.jsdelivr.net/gh/jerryc127/CDN@latest/cover/default_bg.png" onerror="onerror=null;src='/ahuang_blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Tp5整合生成条形码</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/ahuang_blog/img/Misaka.jpg" onerror="this.onerror=null;this.src='/ahuang_blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Ahuang</div><div class="author-info__description">Everything can be expected in the future</div></div><div class="card-info-data site-data is-center"><a href="/ahuang_blog/archives/"><div class="headline">文章</div><div class="length-num">51</div></a><a href="/ahuang_blog/tags/"><div class="headline">标签</div><div class="length-num">35</div></a><a href="/ahuang_blog/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/changad" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:136081905@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">快乐每一天！！！</div></div><div class="sticky_layout"><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/ahuang_blog/2022/04/24/051/" title="项目中一些ThinkPhp的使用小技巧">项目中一些ThinkPhp的使用小技巧</a><time datetime="2022-04-24T10:43:22.000Z" title="发表于 2022-04-24 18:43:22">2022-04-24</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/ahuang_blog/2022/04/08/050/" title="Sql查询排名">Sql查询排名</a><time datetime="2022-04-08T08:24:16.000Z" title="发表于 2022-04-08 16:24:16">2022-04-08</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/ahuang_blog/2022/03/06/049/" title="ThinkPhp的跨域问题">ThinkPhp的跨域问题</a><time datetime="2022-03-06T04:40:38.000Z" title="发表于 2022-03-06 12:40:38">2022-03-06</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/ahuang_blog/2021/11/13/048/" title="Nginx关于Socket的配置">Nginx关于Socket的配置</a><time datetime="2021-11-13T07:02:15.000Z" title="发表于 2021-11-13 15:02:15">2021-11-13</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/ahuang_blog/2021/10/28/047/" title="Node.js之Express关于socket.io的使用">Node.js之Express关于socket.io的使用</a><time datetime="2021-10-28T04:36:17.000Z" title="发表于 2021-10-28 12:36:17">2021-10-28</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2018 - 2023 By Ahuang</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">Everything can be expected in the future!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/ahuang_blog/js/utils.js"></script><script src="/ahuang_blog/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="/ahuang_blog/js/search/local-search.js"></script><div class="js-pjax"></div><script src="https://cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script><script async src="https://cdn.jsdelivr.net/npm/js-heo@1.0.11/categoryBar/categoryBar.js"></script><script src="/blog/js/categoryBar.js"><script defer="defer" id="fluttering_ribbon" mobile="true" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = true;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="true"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script data-pjax>
  function butterfly_clock_injector_config(){
    var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
    var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img class="entered loading" id="card-clock-loading" src="/ahuang_blog/img/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading"/></div></div></div></div></div>';
    console.log('已挂载butterfly_clock')
    parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var flag = 0;

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_clock_injector_config();
  }
  else if (epage === cpage){
    butterfly_clock_injector_config();
  }
  </script><script src="https://pv.sohu.com/cityjson?ie=utf-8"></script><script data-pjax src="https://npm.elemecdn.com/hexo-butterfly-clock/lib/clock.min.js"></script><!-- hexo injector body_end end --></body></html>